var t = require("./core");
Component({
  data: {
    list: []
  },
  lifetimes: {
    attached: function () {
      var e = this;
      this.unSubscribe = t.store.subscribe((function (t, i, n) {
        return new Promise((function (o, s) {
          e.resolve = o, e.reject = s, e.onShow(t, i, n)
        }))
      }))
    },
    detached: function () {
      this.unSubscribe && this.unSubscribe()
    }
  },
  methods: {
    onShow: function (t, e, i) {
      var n = this,
        o = this.data.list;
      this.setData({
        list: o.concat({
          type: e,
          options: t,
          visible: !1,
          modalKey: i
        })
      }), setTimeout((function () {
        return n.onUpdate(i, !0)
      }), 50)
    },
    onResolve: function (t) {
      var e = this,
        i = t.detail.modalKey;
      this.onUpdate(i, !1), setTimeout((function () {
        e.onRemove(i), e.resolve()
      }), 500)
    },
    onReject: function (t) {
      var e = this,
        i = t.detail.modalKey;
      this.onUpdate(i, !1), setTimeout((function () {
        e.onRemove(i), e.reject()
      }), 500)
    },
    onUpdate: function (t, e) {
      this.data.list.find((function (e) {
        return e.modalKey === t
      })).visible = e, this.setData({
        list: this.data.list.concat()
      })
    },
    onRemove: function (t) {
      this.setData({
        list: this.data.list.filter((function (e) {
          return e.modalKey !== t
        }))
      })
    },
    onAction: function (t) {
      var e = this,
        i = t.detail,
        n = i.type,
        o = i.modalKey;
      this.onUpdate(o, !1), setTimeout((function () {
        e.onRemove(o), "sure" === n ? e.resolve() : "cancel" !== n && "close" !== n || e.reject(n)
      }), 500)
    }
  }
});